/**
 *功能: 全局路由拦截器
 *
 */
// import store from '../store';

const topbar = require('topbar');

// 设置路由白名单
const whiteList = ['login', 'forget'];

const beforeEach = async (to, from, next) => {
  topbar.show();
  /*
  const token = window.localStorage.getItem('token');
  // console.log("to", to);
  // console.log("from", from);
  // console.log("to", to.meta.pathId);

  // 检测用户token是否存在，塞入请求header
  if (token && token !== 'undefined') {
    console.log('user is login');
    if (to.meta.pathId) {
      // 数据是否已经准备好
      if (store.getters['user/pathIds'].length === 0) {
        const data = await store.dispatch('user/storeUserPath');
        console.log('mm', data);
        if (!data['success']) {
          next('/login');
          return;
        }
      }
      // 权限限制
      if (!store.getters['user/pathIds'].includes(to.meta.pathId)) {
        console.log('不存在');
        // 不在权限id数组里，中断跳转
        next(false);
        topbar.hide();
        return;
      }
    }
  } else if (whiteList.indexOf(to.name) === -1) {
    next(`/login?redirect=${to.path}`);
    return;
  }*/
  next();
};

const afterEach = () => {
  topbar.hide();
  // document.getElementById('nb-global-spinner').style.display = 'none';
};

export { beforeEach, afterEach };
